//
//  MainViewController.m
//  project_delicious
//
//  Created by dlios on 15-3-21.
//  Copyright (c) 2015年 lanou3g.com 蓝鸥科技. All rights reserved.
//

#import "MainViewController.h"
#import "FoodTherapyViewController.h"
#import "SkipViewController.h"
#import "CollectionViewController.h"
#import "FoodDDViewController.h"
#import "FoodDetailsViewController.h"
#import "TheFoodDetailsViewController.h"
#import "MainCollectionViewCell.h"
#import "MyCollectionReusableView.h"
#import "SearchViewController.h"
#import "UIColor+AddColor.h"


@interface MainViewController ()<UIScrollViewDelegate, UICollectionViewDataSource, UICollectionViewDelegate, UICollectionViewDelegateFlowLayout, UIAlertViewDelegate>
@property (nonatomic, strong) NSMutableArray *cellSizes;
@property (nonatomic, retain) NSMutableDictionary *dic;
@property (nonatomic, retain) UIImageView *theImageView;
@property (nonatomic, retain) UIScrollView *myScrollView;
@property (nonatomic, retain) NSMutableArray *arr;
@property (nonatomic, retain) NSString *strId1;
@property (nonatomic, retain) NSString *strId2;
@property (nonatomic, retain) NSString *strId3;
@property (nonatomic, retain) NSMutableArray *arr1;
@property (nonatomic, retain) UICollectionView *collection;
@property (nonatomic, retain) NSMutableArray *nameArr;

@property (nonatomic, retain) MBProgressHUD *hud;

@end

@implementation MainViewController
- (void)dealloc
{
    [_nameArr release];
    [_collection release];
    [_arr1 release];
    [_strId1 release];
    [_strId2 release];
    [_strId3 release];
    [_arr release];
    [_myScrollView release];
    [_theImageView release];
    [_dic release];
    
    [_hud release];
    [super dealloc];
}
//字符串转URL
- (NSURL *)strChangeUrl:(NSString *)str
{
    str = [str stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    NSURL *url = [NSURL URLWithString:str];
    return url;
}

//转菊花
- (void)mbHud
{  
    self.hud = [[MBProgressHUD alloc] initWithView:self.view];
    _hud.labelText = @"Loading...";
    _hud.mode = MBProgressHUDModeIndeterminate;
    //_hud.detailsLabelText = @"正在为您加载";
    [self.view addSubview:_hud];
    [_hud release];
    [_hud show:YES];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    //self.view.backgroundColor = [UIColor redColor];
    //转菊花
    [self mbHud];
    
    self.title = @"首页";
    //右侧搜索界面
    self.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"search.png"] style:UIBarButtonItemStylePlain target:self action:@selector(barButtonAction:)] autorelease];
    
    
    //背景图片
    self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"IMG_1345.JPG"]];
    //导航栏是否为透明的(YES?NO)
    self.navigationController.navigationBar.translucent = NO;
    self.navigationController.navigationBar.backgroundColor = [UIColor clearColor];
    //是否隐藏tabbar(YES?NO)
    self.tabBarController.tabBar.hidden = NO;
    //是否为透明的(YES?NO)
    self.tabBarController.tabBar.translucent = NO;
    
    
    //首页的地址
    NSString *firStr = @"http://121.40.54.251:80/HandheldKitchen/api/home/tblHomepageVegetable!getHomeVegetableList.do?is_traditional=0&page=1&pageRecord=3&phonetype=2";
    //AF解析
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    self.arr1 = [NSMutableArray array];
    [manager GET:firStr parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
        //NSLog(@"成功%@", responseObject);
        //数据
        NSMutableArray *dataArr = [responseObject valueForKey:@"data"];
        //NSLog(@"%@", dataArr);
        self.arr1 = dataArr;
        NSLog(@"%ld", self.arr1.count);
        //主页面的scrollview
        UIScrollView *mainScrillView = [[UIScrollView alloc] initWithFrame:self.view.bounds];
        mainScrillView.delegate = self;
        mainScrillView.showsVerticalScrollIndicator = NO;
        [self.view addSubview:mainScrillView];
        [mainScrillView release];
        
        
        //动态图片
{
//        NSMutableArray *morArr = [NSMutableArray array];
//        for (NSInteger i = 0; i < 45; i++) {
//            UIImage *image = [UIImage imageNamed:[NSString stringWithFormat:@"mor%d.jpg", i + 1]];
//            [morArr addObject:image];
//        }
//        
//        NSMutableArray *noonArr = [NSMutableArray array];
//        for (NSInteger i = 0; i < 3; i++) {
//            UIImage *image = [UIImage imageNamed:[NSString stringWithFormat:@"noon%d.jpg", i + 1]];
//            [noonArr addObject:image];
//        }
//        
//        NSMutableArray *nightArr = [NSMutableArray array];
//        for (NSInteger i = 0; i < 19; i++) {
//            UIImage *image = [UIImage imageNamed:[NSString stringWithFormat:@"night%d.jpg", i + 1]];
//            [nightArr addObject:image];
//        }
//        //获取当地时间
//        NSDate *localDate = [NSDate dateWithTimeIntervalSinceNow:28800];
//        NSString *string = [NSString stringWithFormat:@"%@", localDate];
//        NSRange range = NSMakeRange(11, 8);
//        NSString *str = [string substringWithRange:range];
//        NSRange range1 = NSMakeRange(0, 2);
//        NSString *hour = [str substringWithRange:range1];
//        NSInteger a = [hour integerValue];

    //小麦
    self.theImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT  / 3)];
    self.theImageView.image = [UIImage imageNamed:@"QQ20150403-4.png"];
    //[mainScrillView addSubview:self.theImageView];
    [mainScrillView addSubview:self.theImageView];
    [_theImageView release];
//        if (a > 0 && a <= 10) {
//            
//            self.theImageView.animationImages = morArr;
//            self.theImageView.animationDuration = 5;
//            [self.theImageView startAnimating];
//            [mainScrillView addSubview:self.theImageView];
//            [_theImageView release];
//        } else if (a > 10 && a <= 16){
//            
//            self.theImageView.animationImages = noonArr;
//            self.theImageView.animationDuration = 1;
//            [self.theImageView startAnimating];
//            [mainScrillView addSubview:self.theImageView];
//            [_theImageView release];
//        } else if (a > 16 && a <= 24){
//            self.theImageView.animationImages = nightArr;
//            self.theImageView.animationDuration = 3;
//            [self.theImageView startAnimating];
//            [mainScrillView addSubview:self.theImageView];
//            [_theImageView release];
//        }
    
}
        
        
        //流式布局
        UICollectionViewFlowLayout *flow = [[UICollectionViewFlowLayout alloc] init];
        flow.itemSize = CGSizeMake((self.view.frame.size.width - 50) / 3, self.view.frame.size.height / 5);
        flow.sectionInset = UIEdgeInsetsMake(5, 5, 5, 5);
        flow.headerReferenceSize = CGSizeMake(self.view.frame.size.width - 10, self.view.frame.size.height / 12);
        //下面的collectionview
        //self.collection = [[UICollectionView alloc] initWithFrame:CGRectMake(5, self.theImageView.frame.size.height, self.view.frame.size.width - 10, (flow.headerReferenceSize.height + flow.itemSize.height + 10) * (dataArr.count - 1)) collectionViewLayout:flow];
        self.collection = [[UICollectionView alloc] initWithFrame:CGRectMake(0, self.theImageView.frame.size.height, self.view.frame.size.width, (flow.headerReferenceSize.height + flow.itemSize.height + 10) * (dataArr.count - 1)) collectionViewLayout:flow];
        //_collection.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"coB.jpg"]];
        _collection.backgroundColor = [UIColor clearColor];
        _collection.delegate = self;
        _collection.dataSource = self;
        _collection.scrollEnabled = NO;
        [mainScrillView addSubview:_collection];
        [_collection release];
        [_collection registerClass:[MainCollectionViewCell class] forCellWithReuseIdentifier:@"guo"];
        //collectionview的header
        [_collection registerClass:[MyCollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"ReusableView"];
        //[self.view bringSubviewToFront:_collection];
        
        //偏移
        mainScrillView.contentSize = CGSizeMake(0, _collection.frame.origin.y + (flow.headerReferenceSize.height + flow.itemSize.height + 10) * (dataArr.count - 1));
        
        self.nameArr = [NSMutableArray arrayWithObjects:@"散尽朝来汤饼客", @"炎凉变诈都休问", @"任我逍遥过百春", @"碧油煎出嫩黄深", @"放箸未觉全盘空", nil];
        [_hud removeFromSuperview];
        
        
        
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        NSLog(@"失败");
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:@"请检查网络连接" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil];
        [alert show];
        
    }];
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    [self viewDidLoad];
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 0) {
        //卖汤汤
        FoodDetailsViewController *foodView = [[FoodDetailsViewController alloc] init];
        foodView.hidesBottomBarWhenPushed = YES;
        
        NSString *str1 = [[[[self.arr1 objectAtIndex:indexPath.section] objectForKey:@"vegetableList"] objectAtIndex:indexPath.item] objectForKey:@"vegetable_id"];
        NSInteger n = [str1 integerValue];
        //竖拉条页面
        NSString *str = [NSString stringWithFormat:@"http://121.40.54.251:80/HandheldKitchen/api/more/hotwater!getHotwaterDetail.do?is_traditional=0&id=%ld&phonetype=2", (long)n];
        foodView.str = str;
//
        NSLog(@"0");
        [self.navigationController pushViewController:foodView animated:YES];
        [foodView release];
    } else if (indexPath.section == 1) {
        TheFoodDetailsViewController *foodView = [[TheFoodDetailsViewController alloc] init];
        foodView.hidesBottomBarWhenPushed = YES;
        NSString *vegetable_id = [[[[self.arr1 objectAtIndex:indexPath.section] objectForKey:@"vegetableList"] objectAtIndex:indexPath.item] objectForKey:@"vegetable_id"];
        
        NSString *preStr = @"http://121.40.54.251:80/HandheldKitchen/api/vegetable/tblvegetable!getTblVegetables.do?vegetable_id=";
        NSString *suffStr = @"&phonetype=2&user_id=&is_traditional=0";
        NSString *str = [[preStr stringByAppendingString:vegetable_id] stringByAppendingString:suffStr];
        //食物详情页面
        NSString *preStrMat = @"http://121.41.84.91:80/HandheldKitchen/api/vegetable/tblvegetable!getIntelligentChoice.do?vegetable_id=";
        NSString *suffStrMat = @"&type=1&phonetype=0&is_traditional=0";
        NSString *str1 = [[preStrMat stringByAppendingString:vegetable_id] stringByAppendingString:suffStrMat];
        NSString *preStrCook = @"http://121.41.84.91:80/HandheldKitchen/api/vegetable/tblvegetable!getIntelligentChoice.do?vegetable_id=";
        NSString *suffStrCook = @"&type=2&phonetype=0&is_traditional=0";
        foodView.str = str;
        foodView.str1 = str1;
        //做法页面
        foodView.fid = [[preStrCook stringByAppendingString:vegetable_id] stringByAppendingString:suffStrCook];
//
        NSLog(@"1");
        [self.navigationController pushViewController:foodView animated:YES];
        [foodView release];
        
        
    } else if (indexPath.section == 2) {
        FoodDDViewController *foodView = [[FoodDDViewController alloc] init];
        foodView.hidesBottomBarWhenPushed = YES;
        
        NSString *preStr = @"http://121.41.87.202:80/HandheldKitchen/api/vegetable/tblvegetable!getTblVegetables.do?vegetable_id=";
        NSString *suffStr = @"&phonetype=2&user_id=&is_traditional=0";
        
        NSString *preStrMat = @"http://121.41.87.202:80/HandheldKitchen/api/vegetable/tblvegetable!getIntelligentChoice.do?vegetable_id=";
        NSString *suffStrMat = @"&type=1&phonetype=0&is_traditional=0";
        NSString *preStrCook = @"http://121.41.87.202:80/HandheldKitchen/api/vegetable/tblvegetable!getIntelligentChoice.do?vegetable_id=";
        NSString *suffStrCook = @"&type=2&phonetype=0&is_traditional=0";
        
        NSString *vegetable_id = [[[[self.arr1 objectAtIndex:indexPath.section] objectForKey:@"vegetableList"] objectAtIndex:indexPath.item] objectForKey:@"vegetable_id"];
        NSString *str = [[preStr stringByAppendingString:vegetable_id] stringByAppendingString:suffStr];
        NSString *str1 = [[preStrMat stringByAppendingString:vegetable_id] stringByAppendingString:suffStrMat];
        //NSLog(@"===++++====+++%@", str1);
        foodView.str = str;
        foodView.str1 = str1;
        foodView.fid = [[preStrCook stringByAppendingString:vegetable_id] stringByAppendingString:suffStrCook];
        [self.navigationController pushViewController:foodView animated:YES];
        [foodView release];
//
        NSLog(@"2");
    
        }  else if (indexPath.section == 3) {
            TheFoodDetailsViewController *foodView = [[TheFoodDetailsViewController alloc] init];
            
            NSString *vegetable_id = [[[[self.arr1 objectAtIndex:indexPath.section] objectForKey:@"vegetableList"] objectAtIndex:indexPath.item] objectForKey:@"vegetable_id"];
            foodView.hidesBottomBarWhenPushed = YES;
            NSString *preStr = @"http://121.41.84.91:80/HandheldKitchen/api/vegetable/tblvegetable!getTblVegetables.do?vegetable_id=";
            NSString *suffStr = @"&phonetype=2&user_id=&is_traditional=0";

            NSString *preStrMat = @"http://121.41.84.91:80/HandheldKitchen/api/vegetable/tblvegetable!getIntelligentChoice.do?vegetable_id=";
            NSString *suffStrMat = @"&type=1&phonetype=0&is_traditional=0";
            NSString *preStrCook = @"http://121.41.84.91:80/HandheldKitchen/api/vegetable/tblvegetable!getIntelligentChoice.do?vegetable_id=";
            NSString *suffStrCook = @"&type=2&phonetype=0&is_traditional=0";
            NSString *str = [[preStr stringByAppendingString:vegetable_id] stringByAppendingString:suffStr];
            NSString *str1 = [[preStrMat stringByAppendingString:vegetable_id] stringByAppendingString:suffStrMat];
            foodView.str = str;
            foodView.str1 = str1;
            foodView.fid = [[preStrCook stringByAppendingString:vegetable_id] stringByAppendingString:suffStrCook];
//
            NSLog(@"3");
            [self.navigationController pushViewController:foodView animated:YES];
            [foodView release];
    
    
        } else if (indexPath.section == 4) {
            TheFoodDetailsViewController *foodView = [[TheFoodDetailsViewController alloc] init];
            
            foodView.hidesBottomBarWhenPushed = YES;
            NSString *vegetable_id = [[[[self.arr1 objectAtIndex:indexPath.section] objectForKey:@"vegetableList"] objectAtIndex:indexPath.item] objectForKey:@"vegetable_id"];
            
            NSString *preStr = @"http://121.41.84.91:80/HandheldKitchen/api/vegetable/tblvegetable!getTblVegetables.do?vegetable_id=";
            NSString *suffStr = @"&phonetype=2&user_id=&is_traditional=0";

            NSString *preStrMat = @"http://121.41.84.91:80/HandheldKitchen/api/vegetable/tblvegetable!getIntelligentChoice.do?vegetable_id=";
            NSString *suffStrMat = @"&type=1&phonetype=0&is_traditional=0";
            
            NSString *preStrCook = @"http://121.41.88.179:80/HandheldKitchen/api/vegetable/tblvegetable!getIntelligentChoice.do?vegetable_id=";
            NSString *suffStrCook = @"&type=2&phonetype=0&is_traditional=0";
            

            NSString *str = [[preStr stringByAppendingString:vegetable_id] stringByAppendingString:suffStr];
            NSString *str1 = [[preStrMat stringByAppendingString:vegetable_id] stringByAppendingString:suffStrMat];
            foodView.str = str;
            foodView.str1 = str1;
            foodView.fid = [[preStrCook stringByAppendingString:vegetable_id] stringByAppendingString:suffStrCook];
            
//
            NSLog(@"4");
            [self.navigationController pushViewController:foodView animated:YES];
            [foodView release];
            
        }
    
    
    [self.hud hide:YES];
}
//搜索页面
- (void)barButtonAction:(UIBarButtonItem *)barButton
{
    SearchViewController *search = [[SearchViewController alloc] init];
    //self.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:search animated:YES];
    [search release];
}


- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return  3;
}
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
    return self.arr1.count - 1;
}
- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath
{
    //collectionview的header
    UICollectionReusableView *headerCiew = nil;
    
    //自定义header类
    MyCollectionReusableView *reus = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"ReusableView" forIndexPath:indexPath];
    
    NSString *picStr1 = [[self.arr1 objectAtIndex:indexPath.section] objectForKey:@"imageFilename"];
    [reus.myImageView setImageWithURL:[self strChangeUrl:picStr1]];
    reus.label.text = [self.nameArr objectAtIndex:indexPath.section];
    //    reus.backImageView.image = [UIImage imageNamed:@"1313.jpg"];
    [reus.button addTarget:self action:@selector(buttonActionCheckAll:) forControlEvents:UIControlEventTouchUpInside];
    reus.backImageView.image = [UIImage imageNamed:@"QQ20150403-1.png"];
    [reus bringSubviewToFront:reus.myImageView];
    [reus bringSubviewToFront:reus.label];
    //查看全部的button
    reus.button.tag = indexPath.section + 1000;
    headerCiew = reus;
    return headerCiew;
    
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    MainCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"guo" forIndexPath:indexPath];
    NSString *str = [[[[self.arr1 objectAtIndex:indexPath.section] objectForKey:@"vegetableList"] objectAtIndex:indexPath.item] objectForKey:@"imagePathThumbnails"];
    [cell.picImageView setImageWithURL:[self strChangeUrl:str]];
    cell.nameLabel.text = [[[[self.arr1 objectAtIndex:indexPath.section] objectForKey:@"vegetableList"] objectAtIndex:indexPath.item] objectForKey:@"name"];
    cell.nameLabel.font = [UIFont systemFontOfSize:10];
    cell.layer.cornerRadius = 0;
    cell.picImageView.layer.masksToBounds = YES;
    cell.picImageView.layer.cornerRadius = cell.frame.size.height*2/5;
    
    cell.backgroundColor = [UIColor clearColor];
    //NSLog(@"%------ld", indexPath.section);
    //NSLog(@"%@", str);
    
    return cell;
    
}

- (void)buttonActionCheckAll:(UIButton *)button
{
    //散尽朝来汤饼客
    if (button.tag == 1000) {
        
        SkipViewController *skip = [[SkipViewController alloc] init];
        skip.tag = button.tag;
        skip.hidesBottomBarWhenPushed = YES;
        [self.navigationController pushViewController:skip animated:YES];
        [skip release];
        //任我逍遥过百春
    } else if (button.tag == 1002){
        FoodTherapyViewController *food = [[FoodTherapyViewController alloc] init];
        food.hidesBottomBarWhenPushed = YES;
        [self.navigationController pushViewController:food animated:YES];
        [food release];
        //碧油煎出嫩黄深
    } else if (button.tag == 1003) {
        CollectionViewController *collection = [[CollectionViewController alloc] init];
        collection.hidesBottomBarWhenPushed = YES;
        NSString *str = @"http://121.41.87.4:80/HandheldKitchen/api/more/tblmonthlypopinfo!get.do?phonetype=0&year=2015&month=03&user_id=&page=1&pageRecord=12&is_traditional=0";
        collection.str = str;
        NSString *reStrP = @"http://121.41.87.4:80/HandheldKitchen/api/more/tblmonthlypopinfo!get.do?phonetype=0&year=2015&month=03&user_id=&page=";
        NSString *reStrS = @"&pageRecord=12&is_traditional=0";
        collection.reStrP = reStrP;
        collection.reStrS = reStrS;
        
        
        NSString *preStr = @"http://121.41.84.91:80/HandheldKitchen/api/vegetable/tblvegetable!getTblVegetables.do?vegetable_id=";
        NSString *suffStr = @"&phonetype=2&user_id=&is_traditional=0";
        collection.preStr = preStr;
        collection.suffStr = suffStr;
        NSString *preStrMat = @"http://121.41.84.91:80/HandheldKitchen/api/vegetable/tblvegetable!getIntelligentChoice.do?vegetable_id=";
        NSString *suffStrMat = @"&type=1&phonetype=0&is_traditional=0";
        collection.preStrMat = preStrMat;
        collection.suffStrMat = suffStrMat;
        NSString *preStrCook = @"http://121.41.84.91:80/HandheldKitchen/api/vegetable/tblvegetable!getIntelligentChoice.do?vegetable_id=";
        NSString *suffStrCook = @"&type=2&phonetype=0&is_traditional=0";
        collection.preStrCook = preStrCook;
        collection.suffStrCook = suffStrCook;
        [self.navigationController pushViewController:collection animated:YES];
        [collection release];
        //放箸未觉全盘空
    } else if (button.tag == 1004) {
        CollectionViewController *collection = [[CollectionViewController alloc] init];
        collection.hidesBottomBarWhenPushed = YES;
        NSString *str = @"http://121.41.88.179:80/HandheldKitchen/api/vegetable/tblvegetable!getHotTblVegetable.do?page=1&pageRecord=6&phonetype=0&is_traditional=0&user_id=";
        
        collection.str = str;
        NSString *reStrP = @"http://121.41.88.179:80/HandheldKitchen/api/vegetable/tblvegetable!getHotTblVegetable.do?page=";
        NSString *reStrS = @"&pageRecord=6&phonetype=0&is_traditional=0&user_id=";
        collection.reStrP = reStrP;
        collection.reStrS = reStrS;
        
        
        NSString *preStr = @"http://121.41.88.179:80/HandheldKitchen/api/vegetable/tblvegetable!getTblVegetables.do?vegetable_id=";
        NSString *suffStr = @"&phonetype=2&user_id=&is_traditional=0";
        collection.preStr = preStr;
        collection.suffStr = suffStr;
        NSString *preStrMat = @"http://121.41.88.179:80/HandheldKitchen/api/vegetable/tblvegetable!getIntelligentChoice.do?vegetable_id=";
        NSString *suffStrMat = @"&type=1&phonetype=0&is_traditional=0";
        collection.preStrMat = preStrMat;
        collection.suffStrMat = suffStrMat;
        
        NSString *preStrCook = @"http://121.41.88.179:80/HandheldKitchen/api/vegetable/tblvegetable!getIntelligentChoice.do?vegetable_id=";
        NSString *suffStrCook = @"&type=2&phonetype=0&is_traditional=0";
        collection.preStrCook = preStrCook;
        collection.suffStrCook = suffStrCook;
        [self.navigationController pushViewController:collection animated:YES];
        [collection release];
        //炎凉变诈都休问
    } else if (button.tag == 1001) {
        CollectionViewController *collection = [[CollectionViewController alloc] init];
        collection.hidesBottomBarWhenPushed = YES;
        NSString *str = @"http://121.41.87.4:80/HandheldKitchen/api/vegetable/tblvegetable!getInfo.do?phonetype=0&catalog_id=&page=1&pageRecord=6&is_traditional=0&user_id=";
        collection.str = str;
        NSString *reStrP = @"http://121.41.87.4:80/HandheldKitchen/api/vegetable/tblvegetable!getInfo.do?phonetype=0&catalog_id=&page=";
        NSString *reStrS = @"&pageRecord=6&is_traditional=0&user_id=";
        collection.reStrP = reStrP;
        collection.reStrS = reStrS;
        
        NSString *preStr = @"http://121.40.54.251:80/HandheldKitchen/api/vegetable/tblvegetable!getTblVegetables.do?vegetable_id=";
        NSString *suffStr = @"&phonetype=2&user_id=&is_traditional=0";
        collection.preStr = preStr;
        collection.suffStr = suffStr;
        NSString *preStrMat = @"http://121.41.84.91:80/HandheldKitchen/api/vegetable/tblvegetable!getIntelligentChoice.do?vegetable_id=";
        NSString *suffStrMat = @"&type=1&phonetype=0&is_traditional=0";
        collection.preStrMat = preStrMat;
        collection.suffStrMat = suffStrMat;
        NSString *preStrCook = @"http://121.41.84.91:80/HandheldKitchen/api/vegetable/tblvegetable!getIntelligentChoice.do?vegetable_id=";
        NSString *suffStrCook = @"&type=2&phonetype=0&is_traditional=0";
        collection.preStrCook = preStrCook;
        collection.suffStrCook = suffStrCook;
        //NSLog(@"炎凉");
        [self.navigationController pushViewController:collection animated:YES];
        [collection release];
    }
    
    
    
    
}
- (void)scrollViewWillBeginDecelerating:(UIScrollView *)scrollView
{
    if (scrollView.contentOffset.x > 375 * (4 - 1)) {
        scrollView.contentOffset = CGPointMake(0, 0);
    }
    if (scrollView.contentOffset.x < 0) {
        scrollView.contentOffset = CGPointMake(375 * (4 - 1), 0);
    }
}
- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    self.navigationController.navigationBar.barTintColor = [UIColor colorFromHexCode:@"FFFFCC"];
    self.tabBarController.tabBar.hidden = NO;
    self.navigationController.navigationBar.hidden = NO;

}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
